import string
import hashlib

BASE62_CHARACTERS = string.digits + string.ascii_lowercase + string.ascii_uppercase
PADDING = BASE62_CHARACTERS[-1]
BASE61_CHARACTERS = BASE62_CHARACTERS[:len(BASE62_CHARACTERS)-1]
BASE = len(BASE61_CHARACTERS)

def id_turn_to_code(num):
    if num == 0:
        return BASE61_CHARACTERS[0]
    arr = []
    while num:
        num, rem = divmod(num, BASE)
        arr.append(BASE61_CHARACTERS[rem])
    return ''.join(reversed(arr))

def code_turn_to_id(short_code):
    num = 0
    for char in short_code:
        num = num * BASE + BASE61_CHARACTERS.index(char)
    return num

def generate_unique_code(id_num):
    hash_obj = hashlib.sha256(str(id_num).encode())
    hash_value = int(hash_obj.hexdigest(), 16)
    code = id_turn_to_code(hash_value)
    code = code.rjust(8, PADDING)
    return code

# 处理冲突的字典
conflict_dict = {}

if __name__ == '__main__':
    set_list = set()
    for i in range(1000):
        code = generate_unique_code(i + 1)
        while code in set_list:
            # 冲突处理，添加后缀
            if code in conflict_dict:
                conflict_dict[code] += 1
            else:
                conflict_dict[code] = 1
            code = f"{code}{conflict_dict[code]}"
        set_list.add(code)
    print(len(set_list))